package com.dd.keel.core.framework.server;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dd.keel.core.common.utils.FileUtil;

/**
 * Node config info
 * @author Kevin.XU
 *
 */
public class NodeConfig {

	final static private Logger LOGGER = LoggerFactory.getLogger(NodeConfig.class);
	
	private String host;
	private int port = 0;
	private String group;
	
	public void init(){
		//read host and port
		String nodeConfigFilePath = FileUtil.retrieveConfigFilepath("node.json");
		String nodeConfigContent = FileUtil.readTextFromFile(nodeConfigFilePath, "UTF-8");
		if(nodeConfigContent==null){
			LOGGER.error("{} read failed",nodeConfigFilePath);
			return ;
		}
		JSONObject jSONObject = JSON.parseObject(nodeConfigContent);
		host = jSONObject.getString("host");
		port = jSONObject.getIntValue("port");
		group = jSONObject.getString("group");
	}

	public String getHost() {
		return host;
	}

	public int getPort() {
		return port;
	}

	public String getGroup() {
		return group;
	}
	
	
}
